package com.upay.android.controller.adapter;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.upay.android.R;
import com.upay.android.controller.helper.Format;
import com.upay.android.domain.group.GroupAccount;

public class GroupAccountArrayAdapter extends ArrayAdapter<GroupAccount> {
	
	/* ---- Instance Variables ---- */
	private Activity context = null;
	private List<GroupAccount> groupAccounts = null;

	/* ---- Constructors ---- */
	
	public GroupAccountArrayAdapter(Activity context, List<GroupAccount> groupAccounts) {
		super(context, R.layout.fragment_row_item_group, groupAccounts);
		this.context = context;
		this.groupAccounts = groupAccounts;
	}
	
	/* ---- Business Methods ---- */
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
	
		if (null == convertView) {
			LayoutInflater inflator = context.getLayoutInflater();
			convertView = inflator.inflate(R.layout.fragment_row_item_group, null);
		}
		
		GroupAccount groupAccount = getItem(position);
		
		TextView groupName = (TextView)convertView.findViewById(R.id.row_group_subscribed_name);
		groupName.setText(groupAccount.getGroup().getName());
		TextView groupDescription = (TextView)convertView.findViewById(R.id.row_group_subscribed_description);
		groupDescription.setText(groupAccount.getGroup().getDescription());
		TextView balanceDescription = (TextView)convertView.findViewById(R.id.row_group_balance);
		Format.drawBalance(balanceDescription, groupAccount.getBalance());
		balanceDescription.setText(groupAccount.getBalance().toString());

		return convertView;
	}
	
	/* ---- Getters and Setters ---- */

	public Activity getContext() {
		return context;
	}

	public void setContext(Activity context) {
		this.context = context;
	}

	public List<GroupAccount> getGroupAccounts() {
		return groupAccounts;
	}

	public void setGroupAccounts(List<GroupAccount> groupAccounts) {
		this.groupAccounts = groupAccounts;
	}

	

	
	
	

}
